home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / GRAPHICS / TS32 / TS32.ZIP / ColorButton.pas < prev    next >
Pascal/Delphi Source File  |  1996-02-02  |  2KB  |  79 lines

  1. (***************************************************
  2. TColorButton->TColorPanel
  3.  
  4. A simple descendant of TColorPanel that provides some
  5. nive default effects for MouseDown and MouseUp.
  6.  
  7. TColorToggle->TColorPanel
  8.  
  9. Another descendant of TColorPanel that acts as a toggle.
  10.  
  11. Properties
  12.  
  13. Down
  14.   Controls the toggle's state.
  15. ***************************************************)
  16.  
  17. unit ColorButton;
  18.  
  19. interface
  20.  
  21. uses
  22.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  23.   ExtCtrls, ColorPanel;
  24.  
  25. type
  26.  
  27.   TColorButton = class( TColorPanel )
  28.   private
  29.      FSaveColor: byte;
  30.   protected
  31.      procedure MouseDown( Button: TMouseButton; Shift: TShiftState; X, Y: Integer ); override;
  32.      procedure MouseUp( Button: TMouseButton; Shift: TShiftState; X, Y: Integer ); override;
  33.   public
  34.   published
  35.      constructor Create( AOwner: TComponent ); override;
  36.   end;
  37.  
  38. procedure Register;
  39.  
  40. implementation
  41.  
  42. (***************************************************
  43. Some new defaults.
  44. ***************************************************)
  45. constructor TColorButton.Create( Aowner: TComponent );
  46. begin
  47.   inherited Create( AOwner );
  48.   BlackOutline := FALSE;
  49.   Rollover := TRUE;
  50. end;
  51.  
  52. (***************************************************
  53. When the button is "pressed" draw in shadow color.
  54. ***************************************************)
  55. procedure TColorButton.MouseDown( Button: TMouseButton; Shift: TShiftState; X, Y: Integer );
  56. begin
  57.   BevelOuter := bvLowered;
  58.   FSaveColor := ColorIndex;
  59.   ColorIndex := ColorIndexShadow;
  60.   inherited MouseDown( Button, Shift, X, Y );
  61. end;
  62.  
  63. (***************************************************
  64. Restore the color when the mouse is lifted.
  65. ***************************************************)
  66. procedure TColorButton.MouseUp( Button: TMouseButton; Shift: TShiftState; X, Y: Integer );
  67. begin
  68.   BevelOuter := bvRaised;
  69.   ColorIndex := FSaveColor;
  70.   inherited MouseUp( Button, Shift, X, Y );
  71. end;
  72.  
  73. procedure Register;
  74. begin
  75.   RegisterComponents( 'Vis', [TColorButton] );
  76. end;
  77.  
  78. end.
  79.